package com.retail.booking.controller;

import com.retail.booking.entity.request.BookingSharePosterConfigRequest;
import com.retail.booking.entity.vo.BookingSharePosterConfigVo;
import com.retail.booking.service.BookingSharePosterConfigService;
import com.retail.core.common.AbstractCommonController;
import com.retail.core.entity.ParamReq;
import com.retail.core.entity.result.PageResult;
import com.retail.core.entity.result.Result;
import com.retail.global.annon.TraceLog;
import com.retail.global.security.LoginUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 海报配置 API
 *
 * @author Administrator
 */
@Api(tags = "海报配置 API")
@RestController
@RequestMapping("/bookingSharePosterConfig")
public class BookingSharePosterConfigController extends AbstractCommonController<BookingSharePosterConfigService, BookingSharePosterConfigRequest, BookingSharePosterConfigVo> {

    private final BookingSharePosterConfigService bookingSharePosterConfigService;

    public BookingSharePosterConfigController(BookingSharePosterConfigService bookingSharePosterConfigService) {
        this.bookingSharePosterConfigService = bookingSharePosterConfigService;
    }

    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(bookingSharePosterConfigService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存海报配置")
    public Result<Integer> save(@RequestBody BookingSharePosterConfigRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.save(bookingSharePosterConfigService, request);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新海报配置")
    public Result<Integer> update(@RequestBody BookingSharePosterConfigRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.update(bookingSharePosterConfigService, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("海报配置-查询")
    public Result<List<BookingSharePosterConfigVo>> listPage(@RequestBody ParamReq req) {
      
        return super.listPage(bookingSharePosterConfigService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("海报配置-统计")
    public Result<Integer> countPage(@RequestBody ParamReq req) {
        req.setManagerDept(LoginUserUtil.getPrincipal().getManagerDept());
        return super.countPage(bookingSharePosterConfigService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("海报配置-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<BookingSharePosterConfigRequest> req) {
        req.setManagerDept(LoginUserUtil.getPrincipal().getManagerDept());
        return super.page(bookingSharePosterConfigService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除海报配置")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(bookingSharePosterConfigService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除海报配置")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(List<Long> ids) {
        return super.batchDelete(bookingSharePosterConfigService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }


    /**
     * 存储状态只能存在一个起作用
     * @return
     */
    @TraceLog()
    @ApiOperation("切换海报状态")
    @PostMapping("/switchStatus")
    public Result<Integer> switchStatus(@RequestBody BookingSharePosterConfigRequest request){
        return bookingSharePosterConfigService.switchStatus(request);
    }
}
